﻿using System.Diagnostics;
using System.Net.Http.Json;
using System.Text;
using YiJingFramework.Annotating.Zhouyi;
using YiJingFramework.EntityRelations.GuaCharacters.Extensions;

Console.OutputEncoding = Encoding.Unicode;

using var client = new HttpClient();
var zhouyi = await client.GetFromJsonAsync<ZhouyiStore>(
    "https://yueyinqiu.github.io/my-yijing-annotation-stores/975345ca/2023-08-02-1.json");
Debug.Assert(zhouyi is not null);

var paddingChar = '　';
for (int i = 1; i <= 64; i++)
{
    var hexagram = zhouyi.GetHexagramByIndex(i.ToString("00"));
    Debug.Assert(hexagram is not null);
    var (upper, lower) = hexagram.SplitToTrigrams(zhouyi);

    Console.Write($"第 {i:00} 卦{paddingChar}" +
            $"上{upper.Name}{upper.Painting.ToUnicodeChar()}" +
            $"下{lower.Name}{lower.Painting.ToUnicodeChar()}{paddingChar}");

    if (upper == lower)
        Console.WriteLine(
            $"{hexagram.Name}{hexagram.Painting.ToUnicodeChar()}为{upper.Nature}");
    else
        Console.WriteLine(
            $"{upper.Nature}{lower.Nature}{hexagram.Name}{hexagram.Painting.ToUnicodeChar()}");
}